﻿<?php 
$dbName = "162_appma";
$server = "localhost";
$user="appma";
$password = "database";
$baseURL = "http://localhost:8080/dbClass/Zabdocx/";

class Util
{
	var $dbName ,$server ,$user,$password,$con;

	function getvalue($parameter)
	{
		$result ="";
		if (isset($_POST[$parameter]))
			$result = $_POST[$parameter];
		if (isset($_GET[$parameter]))
			$result = $_GET[$parameter];

		return $result;
	}

	function Init()
	{

		$this->dbName = "162_appma";
		$this->server = "localhost";
		$this->user="appma";
		$this->password = "database";

		$this->con = mysql_connect($this->server ,$this->user,$this->password);
		if (!$this->con)
		{
			die("Could not connect: " . mysql_error());
		}
		mysql_select_db($this->dbName);

	}

	function Query($query)
	{
		//echo $query;
		return mysql_query($query);
	}

	function Close()
	{
		mysql_close($this->con);
	}

	function uniqueFilename($strExt = '.tmp') 
	{
		if (function_exists('com_create_guid') === true)
		{
			return trim(com_create_guid(), '{}').$strExt;
		}

		$filename = sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', 
			mt_rand(0, 65535), 
			mt_rand(0, 65535), 
			mt_rand(0, 65535), 
			mt_rand(16384, 20479), 
			mt_rand(32768, 49151), 
			mt_rand(0, 65535), 
			mt_rand(0, 65535), 
			mt_rand(0, 65535));
		
		return $filename.$strExt;
	}

	function file_extension($filename)
	{
		return end(explode(".", $filename));
	}


	function get_file_links($filename,$baseURL)
	{
		if($filename=="")
			return "";

		$result ="";
		if(file_exists(getcwd().'\\docs\\'.$filename))
		{
			$result= "<a href='".$baseURL.'/docs/'.$filename."'>Download</a>";
		}

		$ext = $this->file_extension($filename);

		$urlfile =  str_replace($ext,"x10", $filename);

		//echo '.'.$urlfile .'.';

		
		$urlVal = "";
		if(file_exists(getcwd().'\\docs\\'.$urlfile))
		{
			$lines = file(getcwd().'\\docs\\'.$urlfile);
			foreach($lines as $line)
			{
				$urlVal = $line;
			}
		}
		
		if($urlVal!="")
		{
			$result = $result ." <a href='".$urlVal."' target='_blank'>Online</a>";
		}
		return $result;
	}

}
?> 